﻿using System;
using System.Collections.Generic;

using System.Text;
using System.Net;
namespace Ession
{
    public class TcpConnection
    {
        public TcpConnection(string connstr)
        {
            connctionStr = connstr;
            try
            {
                var s = connstr.Split('-');
                if (s.Length >= 3)
                {
                    var local = s[0].Split(':');
                    LocalIP = local[0];
                    LocalPort = int.Parse(local[1]);


                    var remote = s[1].Split(':');
                    RemoteIP = remote[0];
                    RemotePort = int.Parse(remote[1]);

                    this.State = s[2];

                    RemoteName = " ";
                }
            }
            catch (Exception)
            {

                throw new ArgumentException("不正确的字符串");
            }
        }

        private string connctionStr;
        public string LocalIP { get; set; }
        public int LocalPort { get; set; }
        public string RemoteIP { get; set; }
        public int RemotePort { get; set; }
        public string State { get; set; }
        public string RemoteName { get; set; }
        public override string ToString()
        {
            return connctionStr;
        }

        public override bool Equals(object obj)
        {


            if (obj == null || GetType() != obj.GetType())
            {
                return false;
            }
            if (obj.ToString() == this.ToString())
            {
                return true;
            }
            return false;


        }

        // override object.GetHashCode
        public override int GetHashCode()
        {
            // TODO: write your implementation of GetHashCode() here
            throw new NotImplementedException();
            return base.GetHashCode();
        }
    }
}
